package com.tonann.app.controller;

import com.tonann.app.domain.AppFeedBack;
import com.tonann.app.service.IAppFeedBackService;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.core.page.TableDataInfo;
import com.tonann.common.enums.BusinessType;
import com.tonann.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 帮助与反馈Controller
 *
 * @author tonann
 * @date 2023-05-21
 */
@RestController
@RequestMapping("/app/back")
public class AppFeedBackController extends BaseController {
    @Autowired
    private IAppFeedBackService appFeedBackService;

    /**
     * 查询帮助与反馈列表
     */
    @PreAuthorize("@ss.hasPermi('app:back:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppFeedBack appFeedBack) {
        startPage();
        List<AppFeedBack> list = appFeedBackService.selectAppFeedBackList(appFeedBack);
        return getDataTable(list);
    }

    /**
     * 导出帮助与反馈列表
     */
    @PreAuthorize("@ss.hasPermi('app:back:export')")
    @Log(title = "帮助与反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppFeedBack appFeedBack) {
        List<AppFeedBack> list = appFeedBackService.selectAppFeedBackList(appFeedBack);
        ExcelUtil<AppFeedBack> util = new ExcelUtil<AppFeedBack>(AppFeedBack.class);
        util.exportExcel(response, list, "帮助与反馈数据");
    }

    /**
     * 获取帮助与反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:back:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appFeedBackService.selectAppFeedBackById(id));
    }

    /**
     * 新增帮助与反馈
     */
    @PreAuthorize("@ss.hasPermi('app:back:add')")
    @Log(title = "帮助与反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppFeedBack appFeedBack) {
        return toAjax(appFeedBackService.insertAppFeedBack(appFeedBack));
    }

    /**
     * 修改帮助与反馈
     */
    @PreAuthorize("@ss.hasPermi('app:back:edit')")
    @Log(title = "帮助与反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppFeedBack appFeedBack) {
        return toAjax(appFeedBackService.updateAppFeedBack(appFeedBack));
    }

    /**
     * 删除帮助与反馈
     */
    @PreAuthorize("@ss.hasPermi('app:back:remove')")
    @Log(title = "帮助与反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appFeedBackService.deleteAppFeedBackByIds(ids));
    }
}
